<%@page import="com.feib.soeasy.model.Group"%>
<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.Payment"%>
<%@page import="com.feib.soeasy.util.CodeTableUtil"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.feib.soeasy.action.Soez5007ActionBean"%>
<%
Soez5007ActionBean actionBean = (Soez5007ActionBean) request.getAttribute("actionBean");
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
String today = sd.format(Calendar.getInstance().getTime());
%>
<c:choose>
	<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
	<stripes:form name="emailNotioceForm" id="emailNotioceForm" beanclass="com.feib.soeasy.action.Soez5007ActionBean" method="post" onsubmit="javascript: return false;">
	
		<c:set var="lastPageNumber" value="${actionBean.queryResult.totalPageCount}"/>
		<c:set var="currentPageNumber" value="${actionBean.queryResult.pageNumber}"/>
		<c:set var="prePageNumber" value="${actionBean.queryResult.pageNumber - 1}"/>
		<c:set var="nextPageNumber" value="${actionBean.queryResult.pageNumber + 1}"/>
		
		<div id="paginationBar">
			<input type="button" id="firstPageBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
			
		</div>
		<table id="listTable">
		<thead>
			<tr>
				<th>繳費帳號</th>
				<th>客戶名稱</th>
				<th>客戶編號</th>					
				<th>餘額</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
			<tr>			
				<td align="center"><c:out value="${viewObj.payment.virtualAccount}" /></td>
				<td align="left"><c:out value="${viewObj.payment.payerName}" /></td>
				<td align="left"><c:out value="${viewObj.payment.payerId}" /></td>										
				<td align="right">
					<fmt:formatNumber value="${viewObj.avbal}" pattern="##,###" />
				</td>		
				<td>
					<div id="viewPaymentImg-<c:out value='${viewObj.payment.paymentPk}'/>"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
				</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	<div id="paginationBar">
		<input type="button" id="printBtn2" value="列印" />
		<input type="button" id="doDownloadExcelFileBtn" value="下載(Excel)" />
	</div>
	
<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$("[id^='firstPageBtn']").click(function() {
				doQueryAction(1);
			});
			
			$("[id^='prePageBtn']").click(function() {
				doQueryAction(<c:out value='${prePageNumber}'/>);
			});
			
			$("[id^='nextPageBtn']").click(function() {
				doQueryAction(<c:out value='${nextPageNumber}'/>);
			});
			
			$("[id^='lastPageBtn']").click(function() {
				doQueryAction(<c:out value='${lastPageNumber}'/>);
			});

			$('#printBtn2').click(function() {
				//window.print();
				//doQueryPrintAction();
				divPrint('queryResultDiv');//只印目前這筆
			});
			$("#doDownloadExcelFileBtn").click(function() {
				doDownloadExcelMaster();
			});
			
			$("[id^='currentPageText']").change(function() {
				var value = this.value;
				if (value != ''){
					value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(value)) {
						alert('頁數必須是整數');
						return ;
					}
					
					value = parseInt(value, 10);
					
					if (value < 1){
						alert('頁數必須是大於1');
						return ;
					}
					else if (value > <c:out value='${lastPageNumber}'/>){
						alert('頁數必須是小於總頁數 (<c:out value='${lastPageNumber}'/>)');
						return ;
					}
					else if (value != <c:out value='${currentPageNumber}'/>){
						doQueryAction(value);
					}
					
				}
				else{
					alert('頁數不可為空白');
					return ;
				}
			});
			
			
			$("[id^='viewPaymentImg-']").click(function() {
				var paymentPk = this.id.substring(15);
				doQueryDetailAction(paymentPk);
				
			});

			
		});
		//-->
		</script>
		
	</stripes:form>

	</c:when>
	<c:otherwise>
	
		<div id="queryNothingBlockDiv" style="display: none;">
			查無資料
		</div>		
		<table id="listTable">
		<thead>
			<tr>
				<th>繳費帳號</th>
				<th>客戶名稱</th>
				<th>客戶編號</th>			
				<th>餘額</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
	
	</table>
	<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#queryNothingBlockDiv" ).dialog({  title:'<%=UserUtil.getCurrentMenuItemName() %>' ,width: 300, resizable: false, modal: true, buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}  });
		});
		//-->
		</script>		
	</c:otherwise>
</c:choose>